package per.mapt.webservice;

import per.mapt.webservice.vo.User;
import per.mapt.webservice.vo.UserImpl;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

/**
 * Created by mapei on 2017/3/18.
 */
public class ServiceClient {
    private static final QName SERVICE_NAME = new QName("http://webservice.mapt.per/", "HelloService");
    private static final QName PORT_NAME
            = new QName("http://webservice.mapt.per/", "HelloServiceImplPort");

    public static void main(String[] args) throws MalformedURLException {
        Service service = Service.create(new URL("http://localhost:8081/helloService?wsdl"),SERVICE_NAME);
        String endPoint = "http://localhost:8081/helloService";
       service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endPoint);
        HelloService helloService = service.getPort(HelloService.class);
        User user = new UserImpl("World");
        System.out.println(helloService.sayHiToUser(user));

        //say hi to some more users to fill up the map a bit
        user = new UserImpl("Galaxy");
        System.out.println(helloService.sayHiToUser(user));

        user = new UserImpl("Universe");
        System.out.println(helloService.sayHiToUser(user));

        System.out.println();
        System.out.println("Users: ");
        Map<Integer, User> users = helloService.getUsers();
        for (Map.Entry<Integer, User> e : users.entrySet()) {
            System.out.println("  " + e.getKey() + ": " + e.getValue().getName());
        }
    }
}
